package com.bit.frige.DB;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bit.frige.R;

public class MyAdapter2 extends BaseAdapter {
    private Context context;
     private ArrayList<FoodDTO> arrData;
     private LayoutInflater inflater;
     
             public MyAdapter2(Context c, ArrayList<FoodDTO> arr) {
                      this.context = c;
                      this.arrData = arr;
                      inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             }
             public int getCount() {
                     return arrData.size();
             }
             public Object getItem(int position) {
                     return arrData.get(position).getFoodname();
             }
             public long getItemId(int position) {
                     return position;
             }
             public View getView(int position, View convertView, ViewGroup parent) {
                      if(convertView == null){
                       convertView = inflater.inflate(R.layout.listlayout, parent, false);
                      }
              
                      ImageView img = (ImageView)convertView.findViewById(R.id.adapterimg);
                     int cateno = arrData.get(position).getCateno();
                     int Dday=arrData.get(position).getSelflife();
                     if(cateno==0&&Dday>=0){
                         img.setImageResource(R.drawable.food1);
                      }else if(cateno==0&&Dday<0){
                         img.setImageResource(R.drawable.greyfood1);
                      }else if(cateno==1&&Dday>=0){
                         img.setImageResource(R.drawable.food2);
                      }else if(cateno==1&&Dday<0){
                         img.setImageResource(R.drawable.greyfood2);
                      } else if(cateno==2&&Dday>=0){
                         img.setImageResource(R.drawable.food3);
                      } else if(cateno==2&&Dday<0){
                         img.setImageResource(R.drawable.greyfood3);
                      }else if(cateno==3&&Dday>=0){
                         img.setImageResource(R.drawable.food4);
                      }else if(cateno==3&&Dday<0){
                         img.setImageResource(R.drawable.greyfood4);
                      }else if(cateno==4&&Dday>=0){
                         img.setImageResource(R.drawable.food5);
                      }else if(cateno==4&&Dday<0){
                         img.setImageResource(R.drawable.greyfood5);
                      }else if(cateno==5&&Dday>=0){
                         img.setImageResource(R.drawable.food6);
                      }else if(cateno==5&&Dday<0){
                         img.setImageResource(R.drawable.greyfood6);
                      }else if(cateno==6&&Dday>=0){
                         img.setImageResource(R.drawable.food7);
                      }else if(cateno==6&&Dday<0){
                         img.setImageResource(R.drawable.greyfood7);
                      }else if(cateno==7&&Dday>=0){
                         img.setImageResource(R.drawable.food8);
                      }else if(cateno==7&&Dday>=0){
                          img.setImageResource(R.drawable.food8);
                       }else if(cateno==7&&Dday<0){
                    	   img.setImageResource(R.drawable.greyfood9);
             	      }
                      TextView name = (TextView)convertView.findViewById(R.id.adaptername);
                      name.setText(arrData.get(position).getFoodname());
                      
                      TextView day = (TextView)convertView.findViewById(R.id.adapterday);
                      if(Dday>=0){   
                              day.setText("D-"+Dday);   
                      }else if( Dday<0){   
                      Dday= Dday*(-1);   
                      day.setText("D+"+Dday);   
                      }
                      return convertView;
              
             }

    }